package top.lixunda.ecommerce.server.good.api.entity.dto;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.ImmutableMap;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import top.lixunda.common.utils.ObjectValidators;
import top.lixunda.ecommerce.server.business.api.condition.ILambdaConvertQueryWrapperDTO;
import top.lixunda.ecommerce.server.business.api.entity.dto.OrderByDTO;
import top.lixunda.ecommerce.server.good.api.entity.db.OrderReviewDO;
import top.lixunda.ecommerce.server.good.api.entity.db.OrderReviewDetailDO;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 订单评论详细数据条件DTO
 *
 * @author lixunda
 * @version time:2020/3/8 10:03
 */
@ApiModel("订单评论详细数据条件DTO")
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class OrderReviewDetailQueryDTO extends OrderByDTO
        implements ILambdaConvertQueryWrapperDTO<OrderReviewDO, OrderReviewDetailDO> {

    /**
     * 唯一id
     */
    @ApiModelProperty(value = "唯一id")
    private List<Integer> id;

    /**
     * 用户id
     */
    @ApiModelProperty(value = "用户id")
    private List<Integer> userId;

    /**
     * 店铺id
     */
    @ApiModelProperty(value = "店铺id")
    private List<Integer> storeId;

    /**
     * 店铺名称
     */
    @ApiModelProperty(value = "店铺名称")
    private List<String> storeName;

    /**
     * 订单id
     */
    @ApiModelProperty(value = "订单id")
    private List<Integer> orderId;

    /**
     * 描述评分
     */
    @ApiModelProperty(value = "描述评分，总分10分，五颗星")
    private Integer gradeDescMin;

    /**
     * 描述评分
     */
    @ApiModelProperty(value = "描述评分，总分10分，五颗星")
    private Integer gradeDescMax;

    /**
     * 物流评分
     */
    @ApiModelProperty(value = "物流评分，总分10分，五颗星")
    private Integer gradeLogisMin;

    /**
     * 物流评分
     */
    @ApiModelProperty(value = "物流评分，总分10分，五颗星")
    private Integer gradeLogisMax;

    /**
     * 服务评分
     */
    @ApiModelProperty(value = "服务评分，总分10分，五颗星")
    private Integer gradeServiceMin;

    /**
     * 服务评分
     */
    @ApiModelProperty(value = "服务评分，总分10分，五颗星")
    private Integer gradeServiceMax;

    /**
     * 是否匿名
     */
    @ApiModelProperty(value = "是否匿名，默认0，不匿名，0 不匿名 1 匿名")
    private Integer anonymousEnable;

    /**
     * 评论创建时间
     */
    @ApiModelProperty(value = "评论创建时间，即发表评论时间")
    private LocalDateTime timeBegin;

    /**
     * 评论创建时间
     */
    @ApiModelProperty(value = "评论创建时间，即发表评论时间")
    private LocalDateTime timeEnd;

    /**
     * 排序字段映射
     */
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    private static final Map<String, SFunction<OrderReviewDO, ?>> ORDER_REVIEW_COLUMNS =
            new ImmutableMap.Builder<String, SFunction<OrderReviewDO, ?>>()
                    .put("id", OrderReviewDO::getId)
                    .put("userId", OrderReviewDO::getUserId)
                    .put("userName", OrderReviewDO::getUserName)
                    .put("storeId", OrderReviewDO::getStoreId)
                    .put("storeName", OrderReviewDO::getStoreName)
                    .put("orderId", OrderReviewDO::getOrderId)
                    .put("gradeDesc", OrderReviewDO::getGradeDesc)
                    .put("gradeLogis", OrderReviewDO::getGradeLogis)
                    .put("gradeService", OrderReviewDO::getGradeService)
                    .put("content", OrderReviewDO::getContent)
                    .put("time", OrderReviewDO::getTime)
                    .build();

    /**
     * 分页条件，主表
     *
     * @return 条件构造器 LambdaQuerySqlWrapper
     */
    @Override
    public LambdaQueryWrapper<OrderReviewDO> toPageWrapper() {
        LambdaQueryWrapper<OrderReviewDO> wrapper = new LambdaQueryWrapper<>();
        if (ObjectValidators.isNotEmpty(id)) {
            wrapper.and(innerWrapper ->
                    id.forEach(item -> innerWrapper.or()
                            .eq(OrderReviewDO::getId, item)));
        }
        if (ObjectValidators.isNotEmpty(userId)) {
            wrapper.and(innerWrapper ->
                    userId.forEach(item -> innerWrapper.or()
                            .eq(OrderReviewDO::getUserId, item)));
        }
        if (ObjectValidators.isNotEmpty(storeId)) {
            wrapper.and(innerWrapper ->
                    storeId.forEach(item -> innerWrapper.or()
                            .eq(OrderReviewDO::getStoreId, item)));
        }
        if (ObjectValidators.isNotEmpty(storeName)) {
            wrapper.and(innerWrapper ->
                    storeName.forEach(item -> innerWrapper.or()
                            .eq(OrderReviewDO::getStoreName, item)));
        }
        if (ObjectValidators.isNotEmpty(orderId)) {
            wrapper.and(innerWrapper ->
                    orderId.forEach(item -> innerWrapper.or()
                            .eq(OrderReviewDO::getOrderId, item)));
        }
        if (ObjectValidators.isNotEmpty(gradeDescMin)) {
            wrapper.ge(OrderReviewDO::getGradeDesc, gradeDescMin);
        }
        if (ObjectValidators.isNotEmpty(gradeDescMax)) {
            wrapper.le(OrderReviewDO::getGradeDesc, gradeDescMax);
        }
        if (ObjectValidators.isNotEmpty(gradeLogisMin)) {
            wrapper.ge(OrderReviewDO::getGradeLogis, gradeLogisMin);
        }
        if (ObjectValidators.isNotEmpty(gradeLogisMax)) {
            wrapper.le(OrderReviewDO::getGradeLogis, gradeLogisMax);
        }
        if (ObjectValidators.isNotEmpty(gradeServiceMin)) {
            wrapper.ge(OrderReviewDO::getGradeService, gradeServiceMin);
        }
        if (ObjectValidators.isNotEmpty(gradeServiceMax)) {
            wrapper.le(OrderReviewDO::getGradeService, gradeServiceMax);
        }
        if (ObjectValidators.isNotEmpty(anonymousEnable)) {
            wrapper.eq(OrderReviewDO::getAnonymousEnable, anonymousEnable);
        }
        if (ObjectValidators.isNotEmpty(timeBegin)) {
            wrapper.ge(OrderReviewDO::getTime, timeBegin);
        }
        if (ObjectValidators.isNotEmpty(timeEnd)) {
            wrapper.le(OrderReviewDO::getTime, timeEnd);
        }
        dealWithOrderBy(wrapper, ORDER_REVIEW_COLUMNS);
        return wrapper;
    }

    /**
     * 排序字段映射
     */
    @ApiModelProperty(hidden = true)
    @JsonIgnore
    private static final Map<String, SFunction<OrderReviewDetailDO, ?>> ORDER_REVIEW_DETAIL_COLUMNS =
            new ImmutableMap.Builder<String, SFunction<OrderReviewDetailDO, ?>>()
                    .put("id", OrderReviewDetailDO::getId)
                    .put("userId", OrderReviewDetailDO::getUserId)
                    .put("userName", OrderReviewDetailDO::getUserName)
                    .put("storeId", OrderReviewDetailDO::getStoreId)
                    .put("storeName", OrderReviewDetailDO::getStoreName)
                    .put("orderId", OrderReviewDetailDO::getOrderId)
                    .put("gradeDesc", OrderReviewDetailDO::getGradeDesc)
                    .put("gradeLogis", OrderReviewDetailDO::getGradeLogis)
                    .put("gradeService", OrderReviewDetailDO::getGradeService)
                    .put("content", OrderReviewDetailDO::getContent)
                    .put("time", OrderReviewDetailDO::getTime)
                    .put("imageId", OrderReviewDetailDO::getImageId)
                    .put("image", OrderReviewDetailDO::getImage)
                    .put("imageFileId", OrderReviewDetailDO::getImageFileId)
                    .put("imageCreateTime", OrderReviewDetailDO::getImageCreateTime)
                    .put("orderReviewMoreId", OrderReviewDetailDO::getOrderReviewMoreId)
                    .put("moreContent", OrderReviewDetailDO::getMoreContent)
                    .put("moreTime", OrderReviewDetailDO::getMoreTime)
                    .put("moreUserId", OrderReviewDetailDO::getMoreUserId)
                    .put("moreUserName", OrderReviewDetailDO::getMoreUserName)
                    .put("moreImageId", OrderReviewDetailDO::getMoreImageId)
                    .put("moreImageFileId", OrderReviewDetailDO::getMoreImageFileId)
                    .put("moreImageCreateTime", OrderReviewDetailDO::getMoreImageCreateTime)
                    .build();

    /**
     * 查询条件，附表
     *
     * @return 条件构造器 LambdaQuerySqlWrapper
     */
    @Override
    public LambdaQueryWrapper<OrderReviewDetailDO> toQueryWrapper() {
        LambdaQueryWrapper<OrderReviewDetailDO> wrapper = new LambdaQueryWrapper<>();
        if (ObjectValidators.isNotEmpty(id)) {
            wrapper.and(innerWrapper ->
                    id.forEach(item -> innerWrapper.or()
                            .eq(OrderReviewDetailDO::getId, item)));
        }
        if (ObjectValidators.isNotEmpty(userId)) {
            wrapper.and(innerWrapper ->
                    userId.forEach(item -> innerWrapper.or()
                            .eq(OrderReviewDetailDO::getUserId, item)));
        }
        if (ObjectValidators.isNotEmpty(storeId)) {
            wrapper.and(innerWrapper ->
                    storeId.forEach(item -> innerWrapper.or()
                            .eq(OrderReviewDetailDO::getStoreId, item)));
        }
        if (ObjectValidators.isNotEmpty(storeName)) {
            wrapper.and(innerWrapper ->
                    storeName.forEach(item -> innerWrapper.or()
                            .eq(OrderReviewDetailDO::getStoreName, item)));
        }
        if (ObjectValidators.isNotEmpty(orderId)) {
            wrapper.and(innerWrapper ->
                    orderId.forEach(item -> innerWrapper.or()
                            .eq(OrderReviewDetailDO::getOrderId, item)));
        }
        if (ObjectValidators.isNotEmpty(gradeDescMin)) {
            wrapper.ge(OrderReviewDetailDO::getGradeDesc, gradeDescMin);
        }
        if (ObjectValidators.isNotEmpty(gradeDescMax)) {
            wrapper.le(OrderReviewDetailDO::getGradeDesc, gradeDescMax);
        }
        if (ObjectValidators.isNotEmpty(gradeLogisMin)) {
            wrapper.ge(OrderReviewDetailDO::getGradeLogis, gradeLogisMin);
        }
        if (ObjectValidators.isNotEmpty(gradeLogisMax)) {
            wrapper.le(OrderReviewDetailDO::getGradeLogis, gradeLogisMax);
        }
        if (ObjectValidators.isNotEmpty(gradeServiceMin)) {
            wrapper.ge(OrderReviewDetailDO::getGradeService, gradeServiceMin);
        }
        if (ObjectValidators.isNotEmpty(gradeServiceMax)) {
            wrapper.le(OrderReviewDetailDO::getGradeService, gradeServiceMax);
        }
        if (ObjectValidators.isNotEmpty(anonymousEnable)) {
            wrapper.eq(OrderReviewDetailDO::getAnonymousEnable, anonymousEnable);
        }
        if (ObjectValidators.isNotEmpty(timeBegin)) {
            wrapper.ge(OrderReviewDetailDO::getTime, timeBegin);
        }
        if (ObjectValidators.isNotEmpty(timeEnd)) {
            wrapper.le(OrderReviewDetailDO::getTime, timeEnd);
        }
        // 处理排序字段
        dealWithOrderBy(wrapper, ORDER_REVIEW_DETAIL_COLUMNS);
        return null;
    }

}
